﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DLL
{
    public class DAProject
    {
        // Chuỗi kết nối
        string strConnection;

        // SqlConnection
        SqlConnection sqlConn = null;
        private StringBuilder sbCommand = new StringBuilder(String.Empty);

        // Ten bang
        private const string c_table = "project";

        // Ten cot cua bang Hop Dong
        private const string c_project_id = "project_id";
        private const string c_project_name = "project_name";

        public DAProject(string strConnection)
        {
            this.strConnection = strConnection;
        }

        private void OpenConnection()
        {
            sqlConn = new SqlConnection(strConnection);
            sqlConn.Open();
        }

        private void CloseConnection()
        {
            sqlConn.Close();
        }

        public DataSet GetProjects()
        {
            DataSet ds = new DataSet();
            this.OpenConnection();
            sbCommand = new StringBuilder(String.Empty);
            sbCommand.AppendLine("SELECT  project_name");
            sbCommand.AppendLine(",project_id");
            sbCommand.AppendFormat("FROM {0} CT", c_table).AppendLine();
            SqlCommand cmd = new SqlCommand(sbCommand.ToString(), sqlConn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            this.CloseConnection();
            return ds;
        }
    }
}
